import { ref } from "vue";
import { helperUrl } from "./requestAddress";
import Http from './http';
import { ElMessage } from "element-plus";

//获取地址栏参数
export const GetParamUrl = function (name: string) {
  return (
    decodeURIComponent(
      (new RegExp("[?|&]" + name + "=" + "([^&;]+?)(&|#|;|$)").exec(
        location.href
      ) || [, ""])[1].replace(/\+/g, "%20")
    ) || ""
  );
};

//帮助文件方法
export const helperFileMethod = function (helperPath: string) {
  const helperRoute = ref<string>(helperUrl + helperPath);
  window.open(helperRoute.value, '_blank');
}

//根据菜单id获取对应数据列
export const GetMenuColsByMenuId = async function () {
  let data = await GetMenuCols();
  if (data.value.length <= 0)
    ElMessage.warning("无【数据列权限】,请到OverallAuth统一权限分发中心设置");
  return data.value;
}

//获取菜单数据列
async function GetMenuCols() {
  const columns = ref<any>([]);
  const menuKey = GetParamUrl("MenuId");
  await GetTableColsRoleByMenuId({ menuId: menuKey }).then(
    ({ data, code, msg }) => {
      if (code == 200) {
        // columns.value = setMenuCols(data);
        columns.value = data;
      } else {
         ElMessage.error("获取菜单数据列错误");
      }
    }
  )
  return columns;
}

//根据菜单id获取登陆人员菜单数据列
const GetTableColsRoleByMenuId = async function (params?: { menuId: string; }) {
  return await Http.get('/api/SysMenuTableCols/GetTableColsByMenuId', params);
}